/**
 * Reinforcement.java
 *
 * @created Mardi 06/03/2007
 * 
 * @author bbrison
 */

package communication.pack;

import objects.*;

public class Reinforcement extends SMPackage {

    /**
     * The different types of a reinforcement
     */
    public final static int EXPLORATORY = 0;
    public final static int PRIMARY = 1;
    public final static int ALTERNATIVE = 2;
    public final static int NEGATIVE = 3;
    
    /**
     * The type of the reinforcement
     */
    private int _type;

    /**
     * The Sink that wants the Data
     */ 
    private Sink _sink;

    /**
     * The station that first emits the reinforcement
     */
    private Station _origin;

    /**
     * The station that need to be ignored. Used for the braided multipath routing procedure
     */
    private Station _skip;

    public Reinforcement(Station sender, int sequencenb, int hopcount, int requestnb, int ttl, int type, Station orig, Sink sink) {
	super(sender,sequencenb,hopcount,requestnb,REINFORCEMENT,ttl);
	_type = type;
	_origin = orig;
	_sink = sink;
    }

     public Reinforcement(Station sender, int sequencenb, int hopcount, int requestnb, int ttl, int type, Station orig) {
	super(sender,sequencenb,hopcount,requestnb,REINFORCEMENT,ttl);
	_type = type;
	_origin = orig;
     }
    
    public Reinforcement(Station sender, int sequencenb, int hopcount, int requestnb, int ttl, int type, Station orig, Sink sink, Station skip) {
	super(sender,sequencenb,hopcount,requestnb,REINFORCEMENT,ttl);
	_type = type;
	_skip = skip;
	_origin = orig;
	_sink = sink;
    }

    public Reinforcement(Reinforcement r){
	super(r);
	_type = r.getType();
	_origin = r.getOrigin();
	_sink = r.getSink();
	_skip = r.getSkipped();
    }

    /**
     *
     *@return the type of reinforcement
     */
    public int getType() {
	return _type;
    }
   
    /**
     *
     *@return the original station that emits the reinforcement
     */
    public Station getOrigin() {
	return _origin;
    }

    /**
     *
     *@return the station that needs to be ignored
     */
    public Station getSkipped() {
	return _skip;
    }

    public Sink getSink() {
	return _sink;
    }

    public String toString(){
	String info = "REINFORCEMENT : \n" + super.infoPackage();
	switch(_type) {
	case 0:
	    info += "\n" + "reinforcement type : exploratory";
	    break;
	case 1:
	    info += "\n" + "reinforcement type : primary";
	    break;
	case 2:
	    info += "\n" + "reinforcement type : alternative";
	    // info += "\n Station to be skipped : " + _skip.toString();
	    break;
	case 3:
	    info += "\n" + "reinforcement type : negative";
	    break;
	default:
	    info += "\n" + "reinforcement type : ERROR";
	    break;
	}
	info += "\n" + _origin.toString();
	info+= "\n"+ _sink.toString();
	return info;
    }
}
